﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using Convertor.Interface;
using Wpf.CommonTools.SystemExtension;

namespace Convertor
{
    class PluginDetailConverter : IValueConverter
    {
        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return string.Empty;
            }

            string path = ((IPluginPath)value).Path;
            string localPath = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, path);
            Assembly assembly = Assembly.LoadFile(localPath);
            string name = ((IPluginInfo)value).Name;
            string desc = ((IPluginInfo)value).Description;
            string version = assembly.GetName().Version.ToString();
            string company = ((AssemblyCompanyAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyCompanyAttribute), false)).Company;

            string str;
            if (parameter == null)
            {
                str = string.Format("{0}\r\n{1}\r\n{5} {2}\r\n(C){3}\r\n{6} {4}",
                    name,
                    desc,
                    version,
                    company,
                    localPath,
                    UILanguage.FindResource("Help_Version"),
                    UILanguage.FindResource("Help_Path"));
            }
            else
            {
                str = version;
            }
            return str;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
